<template>
  <div class="proDialog">
    <el-dialog title="选择客户"
      :visible.sync="visible"
      width="800px"
      append-to-body
      @close="toCancelBox">
      <el-form class="formList"
        :model="queryParams"
        ref="queryForm"
        :inline="true"
        v-show="showSearch"
        label-width="90px"
        style="padding-top: 0">

        <el-form-item label="客户名称"
          prop="customerName">
          <el-input v-model="queryParams.customerName"
            placeholder="请输入客户名称"
            clearable
            size="small" />
        </el-form-item>

        <el-form-item label="客户手机号"
          prop="phone">
          <el-input v-model="queryParams.phone"
            placeholder="请输入客户名称"
            clearable
            size="small" />
        </el-form-item>

        <el-form-item>
          <el-button type="primary"
            icon="el-icon-search"
            size="mini"
            @click="handleQuery">搜索</el-button>
        </el-form-item>
      </el-form>

      <el-table border
        ref="indexTable"
        :data="infoList"
        tooltip-effect="dark"
        style="width: 100%"
        @selection-change="handleSelectionChange"
        :row-key="bindRowKeys">
        <el-table-column type="selection"
          align="center"
          :reserve-selection="true">
        </el-table-column>

        <el-table-column label="客户名称"
          align="center"
          prop="customerName"
          :show-overflow-tooltip="true"
          min-width="120">

        </el-table-column>
        <el-table-column label="性别"
          align="center"
          prop="customerSexStr"
          :show-overflow-tooltip="true" />

        <el-table-column label="手机号"
          align="center"
          prop="phone"
          :show-overflow-tooltip="true" />

      </el-table>

      <pagination v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
        :page-sizes="pageSizess" />

      <div style="display:flex; justify-content: flex-end;">
        <el-button @click="determine"
          type="primary">确定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>

import {

  listInfoSelf,
} from "@/api/customer/InfoSelf";
export default {
  props: {
    flag: {
      type: Boolean,
    },

  },
  watch: {
    flag (val) {
      this.visible = this.flag;
      this.getList();
    },
  },
  data () {
    return {
      // 显示搜索条件
      showSearch: true,
      datas: null,
      selectedDatas: [],
      pageSizess: [5, 10, 15, 20, 25, 30, 50],
      // 商品信息表格数据
      infoList: [],
      // indexTable: [],
      infoListHistory: [],
      multipleSelection: [],
      total: 0,
      queryParams: {
        pageNum: 1,
        pageSize: 5,
        storeName: null,
        dataStatus: '1',
      },
      visible: false,
      categoryOptions: []
    };
  },
  created () {
    this.visible = this.flag;
    this.getList();

  },
  methods: {
    /** 搜索按钮操作 */
    handleQuery () {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    toCancelBox () {
      this.visible = false;
      this.$emit("toCloseBox", false);
    },
    //回显选中
    greet (selectedData) {
      this.selectedDatas = selectedData;
      this.selectedDatas.forEach((item) => {
        this.$refs.indexTable.toggleRowSelection(item, true);
      });
    },
    bindRowKeys (row) {
      return row.customerUid;
    },
    handleSelectionChange (val) {
      this.datas = this.multipleSelection;
      this.multipleSelection = val
      if (this.datas.length > 0) {
        for (let i = 0; i < this.datas.length; i++) {
          for (let k = 0; k < this.multipleSelection.length; k++) {
            if (this.datas[i].couponId == this.multipleSelection[k].couponId) {
              this.multipleSelection[k] = this.datas[i]
            }
          }
        }
      }
    },
    /** 确定选择商品 */
    determine () {
      if (this.multipleSelection.length == 0) return

      this.$emit("multipleSelection", this.multipleSelection);
      this.infoList.forEach((item) => {
        this.$refs.indexTable.toggleRowSelection(item, false);
      });
      this.$forceUpdate();
      this.open = false;
      setTimeout(() => {
        this.queryParams = {
          pageNum: 1,
          pageSize: 5,
          storeName: null,
          dataStatus: '1',
        }
      }, 300)
    },
    /** 查询商品信息列表 */
    getList () {

      listInfoSelf(this.queryParams).then((response) => {
        this.infoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
  },
};
</script>
<style scoped>
.determine {
  position: relative;
  color: #fff;
}

.pagination-container {
  position: relative;
}

.image-rows {
  width: 80px;
  height: 80px;
}
</style>
